home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 23 / CU Amiga - Super CD-ROM 23 (June 1998).iso / CreatingGames / Utilities / Misc / GMS / GMSDev / Source / Asm / Chunky / 020.Simple.s < prev    next >
Encoding:
Text File  |  1997-12-14  |  10.3 KB  |  334 lines

  1. ;===================================================================================;
  2. ;                                 CHUNKY8 EMULATOR
  3. ;===================================================================================;
  4. ;This c2p routine is the slowest, as it uses simple bit testing/setting
  5. ;instructions.  It has an advantage of no restrictions (any screen width/height is
  6. ;okay).
  7.  
  8. CHUNKYMEM =    MEM_DATA    ;<- Fast memory.
  9.  
  10.     INCDIR    "INCLUDES:"
  11.     INCLUDE    "exec/libraries.i"
  12.     INCLUDE    "exec/initializers.i"
  13.     INCLUDE    "exec/resident.i"
  14.     INCLUDE    "exec/exec_lib.i"
  15.     INCLUDE    "hardware/custom.i"
  16.     INCLUDE    "dpkernel/dpkernel.i"
  17.     INCLUDE    "system/debug.i"
  18.  
  19. CALL    MACRO
  20.     jsr    _LVO\1(a6)
  21.     ENDM
  22.  
  23. ;===================================================================================;
  24. ;                                  MONITOR DRIVER
  25. ;===================================================================================;
  26.  
  27.     STRUCTURE    ChunkyBase,LIB_SIZE
  28.     ULONG    CHK_SegList
  29.     LABEL    CHKBase_SIZEOF
  30.  
  31.     SECTION    "Chunky8",CODE
  32.  
  33. LibPriority =     0
  34.  
  35. CleanExit:        ;If the user tries to run the library, we
  36.     moveq    #$00,d0    ;don't want to crash...
  37.     rts
  38.  
  39. InitDescrip:
  40.     dc.w    RTC_MATCHWORD    ;UWORD rt_matchword
  41.     dc.l    InitDescrip,EndCode    ;APTR  rt_matchtag, rt_endskip
  42.     dc.b    RTF_AUTOINIT,DPKVersion    ;UBYTE rt_flags, rt_version
  43.     dc.b    NT_LIBRARY,LibPriority    ;UBYTE rt_type, rt_pri
  44.     dc.l    LibName,IDString,Init    ;APTR  rt_name, rt_idstring, rt_init
  45.  
  46. LibName:
  47.     dc.b    "020.Simple",0
  48.     even
  49.     dc.b    "$VER: "
  50. IDString:
  51.     dc.b    "Chunky 8 Emulator V0.8",10,0
  52.     even
  53.  
  54. Init:    dc.l    CHKBase_SIZEOF,FunctionTable,DataTable,InitRoutine
  55.  
  56. FunctionTable:
  57. FT:    dc.w    -1,Open-FT,Close-FT,Expunge-FT,Null-FT
  58.     dc.w    LIB_emuRemapFunctions-FT
  59.     dc.w    LIB_emuInitRefresh-FT
  60.     dc.w    LIB_emuFreeRefresh-FT
  61.     dc.w    LIB_emuRefreshScreen-FT
  62.     dc.w    -1
  63.  
  64. DataTable:
  65.     INITBYTE LN_TYPE,NT_LIBRARY
  66.     INITLONG LN_NAME,LibName
  67.     INITBYTE LIB_FLAGS,LIBF_SUMUSED!LIBF_CHANGED
  68.     INITWORD LIB_VERSION,DPKVersion
  69.     INITWORD LIB_REVISION,DPKRevision
  70.     INITLONG LIB_IDSTRING,IDString
  71.     dc.l    0
  72.     even
  73.  
  74. ;===================================================================================;
  75. ;                              INITIALISATION ROUTINE
  76. ;===================================================================================;
  77. ;Requires: a0 = SegList
  78. ;       d0 = Library Base.
  79.  
  80. InitRoutine:
  81.     MOVEM.L    D1-D7/A0-A6,-(SP)    ;SP = Save registers.
  82.     move.l    d0,a5    ;a5 = Store pointer to our base.
  83.     move.l    d0,CHKBase    ;ma = Save pointer to our base.
  84.     move.l    a0,CHK_SegList(a5)    ;a5 = Save pointer to SegList.
  85.     move.l    CHKBase(pc),d0    ;d0 = Return library pointer.
  86. .error    MOVEM.L    (SP)+,D1-D7/A0-A6    ;SP = Return registers.
  87.     rts
  88.  
  89. ;===================================================================================;
  90. ;                                   OPEN LIBRARY
  91. ;===================================================================================;
  92.  
  93. Open:    addq.w    #1,LIB_OPENCNT(a6)    ;Increment lib count.
  94.     bclr    #LIBB_DELEXP,LIB_FLAGS(a6)
  95.     move.l    a6,d0    ;Return library base.
  96.     rts
  97.  
  98. ;===================================================================================;
  99. ;                                  CLOSE LIBRARY
  100. ;===================================================================================;
  101.  
  102. Close:    moveq    #$00,d0    ;This is called whenever someone closes
  103.     subq.w    #1,LIB_OPENCNT(a6)    ;our library.
  104.     bne.s    .Exit
  105.     btst    #LIBB_DELEXP,LIB_FLAGS(a6)
  106.     beq.s    .Exit
  107.     bsr.s    Expunge
  108. .Exit    rts
  109.  
  110. ;===================================================================================;
  111. ;                               EXPUNGE THE LIBRARY
  112. ;===================================================================================;
  113.  
  114. Expunge:
  115.     MOVEM.L    D1-D7/A0-A6,-(SP)    ;SP = Save all registers.
  116.     move.l    a6,a5    ;a5 = Our library base.
  117.     tst.w    LIB_OPENCNT(a5)    ;a5 = Do any programs have us open?
  118.     beq.s    .expunge    ;>> = No, so it's safe to expunge ourselves.
  119.     bset    #LIBB_DELEXP,LIB_FLAGS(a5)
  120.     MOVEM.L    (SP)+,D1-D7/A0-A6    ;SP = Return all registers.
  121.     moveq    #$00,d0
  122.     rts
  123.  
  124. .expunge
  125.     move.l    ($4).w,a6    ;a6 = ExecBase.
  126.     move.l    CHK_SegList(a5),d2    ;d2 = Our segment list.
  127.     move.l    a5,a1    ;a1 = Our library base.
  128.     CALL    Remove    ;>> = Remove it.
  129.     move.l    a5,a1    ;a1 = Our library base.
  130.     moveq    #$00,d0    ;d0 = 00
  131.     move.w    LIB_NEGSIZE(a5),d0    ;d0 = LIB_NEGSIZE(base)
  132.     sub.l    d0,a1    ;a1 = (base)-LIB_NEGSIZE
  133.     add.w    LIB_POSSIZE(a5),d0    ;d0 = (LIB_NEGSIZE)+LIB_POSSIZE
  134.     CALL    FreeMem    ;>> = Free the memory.
  135.     move.l    d2,d0    ;d0 = Pointer to segment list.
  136.     MOVEM.L    (SP)+,D1-D7/A0-A6    ;SP = Return all registers, d0 = seglist.
  137.     rts
  138.  
  139. ;===================================================================================;
  140. ;                                    DO NOTHING
  141. ;===================================================================================;
  142.  
  143. Null:    moveq    #$00,d0
  144.     rts
  145.  
  146. ;===================================================================================;
  147. ;                                FUNCTION REMAPPING
  148. ;===================================================================================;
  149. ;Function: Ignore this function, we will only use it to grab the DPKBase.
  150. ;Requires: d0 = DPKBase.
  151. ;       a6 = Chunky Base.
  152. ;Returns:  Nothing.
  153.  
  154. LIB_emuRemapFunctions:
  155.     move.l    d0,DPKBase    ;ma = Save the DPKBase.
  156.     rts
  157.  
  158. ;===================================================================================;
  159. ;                             INITIALISE C2P ALGORITHM
  160. ;===================================================================================;
  161. ;Function: Initialise the C2P algorithm for emuRefreshScreen().  Note how if the
  162. ;       screen is double buffered, we do not allocate a second chunky buffer.
  163. ;       The reason is because a second planar display buffer already exists, so
  164. ;       having a second chunky buffer has no benefit.
  165. ;Requires: a0 = Screen
  166. ;       a6 = Chunky Base.
  167. ;Returns:  d0 = ErrorCode.
  168.  
  169. LIB_emuInitRefresh:
  170.     MOVEM.L    D1-D7/A0-A6,-(SP)    ;SP = Return used registers.
  171.     move.l    DPKBase(pc),a6    ;a6 = DPKBase.
  172.     move.l    GS_Bitmap(a0),a4
  173.  
  174.     ;Move the planar screen displays (allocated in AddScreen()) to
  175.     ;GS_EMemPtrX.
  176.  
  177.     move.l    GS_MemPtr1(a0),GS_EMemPtr1(a0)
  178.     move.l    GS_MemPtr2(a0),GS_EMemPtr2(a0)
  179.     move.l    GS_MemPtr3(a0),GS_EMemPtr3(a0)
  180.  
  181.     ;Allocate the chunky memory, place it in GS_MemPtrX fields and store
  182.     ;the pointers in GS_EFreeX fields to free it later.
  183.  
  184.     move.w    BMP_Width(a4),d0    ;d0 = PicWidth
  185.     mulu    BMP_Height(a4),d0    ;d0 = (PicWidth)*PicHeight
  186.     moveq    #CHUNKYMEM,d1    ;d1 = Memory Type (see definition).
  187.     CALL    AllocMemBlock    ;>> = Go get the chunky memory.
  188.     move.l    d0,GS_EFree1(a0)    ;a4 = Store chunky buffer for freemem.
  189.     move.l    d0,GS_MemPtr1(a0)    ;a0 = Store chunky buffer #1.
  190.     beq.s    .error    ;>> = Memory allocation error.
  191.  
  192.     move.l    GS_Attrib(a0),d2    ;d2 = Screen attributes.
  193.     and.l    #DBLBUFFER,d2    ;d2 = Double buffer?
  194.     beq.s    .done    ;>> = No, finished.
  195.     move.l    d0,GS_MemPtr2(a0)    ;a0 = Store chunky buffer #1.
  196.  
  197. .done    MOVEM.L    (SP)+,D1-D7/A0-A6    ;SP = Return used registers.
  198.     moveq    #ERR_SUCCESS,d0
  199.     rts
  200.  
  201. .error    MOVEM.L    (SP)+,D1-D7/A0-A6    ;SP = Return used registers.
  202.     moveq    #ERR_FAILED,d0
  203.     rts
  204.  
  205. ;===================================================================================;
  206. ;                            DE-INITIALISE C2P ALGORITHM
  207. ;===================================================================================;
  208. ;Function: Free any allocations we made for the C2P routine.
  209. ;Requires: a0 = Screen
  210. ;       a6 = Chunky Base.
  211. ;Returns:  Nothing.
  212.  
  213. LIB_emuFreeRefresh:
  214.     MOVEM.L    D0/A6,-(SP)    ;SP = Save used registers.
  215.     move.l    DPKBase(pc),a6    ;a6 = DPKBase.
  216.     move.l    GS_EFree1(a0),d0    ;d0 = Screen memory 1 (C2P)
  217.     CALL    FreeMemBlock    ;>> = Free screen memory.
  218.     move.l    GS_EFree2(a0),d0    ;d0 = Screen memory 2 (C2P)
  219.     CALL    FreeMemBlock    ;>> = Free screen memory.
  220.     move.l    GS_EFree3(a0),d0    ;d0 = Screen memory 3 (C2P)
  221.     CALL    FreeMemBlock    ;>> = Free screen memory.
  222.     MOVEM.L    (SP)+,D0/A6    ;SP = Return used registers.
  223.     rts
  224.  
  225. ;===================================================================================;
  226. ;                              C2P CONVERSION ROUTINE
  227. ;===================================================================================;
  228. ;Function: Do the C2P process.
  229. ;Requires: a0 = Screen
  230. ;       a6 = Chunky Base.
  231. ;Returns:  Nothing.
  232.  
  233. LIB_emuRefreshScreen:
  234.     MOVEM.L    D0-D7/A0-A6,-(SP)    ;SP = Save used registers.
  235.     move.l    DPKBase(pc),a6    ;a6 = DPKBase.
  236.     move.l    GS_Bitmap(a0),a4    ;a4 = Bitmap
  237.     move.w    BMP_ByteWidth(a4),d5    ;d5 = PicWidth    [Chunky]    [320]
  238.     mulu    BMP_Height(a4),d5    ;d5 = (PicWidth)*PicHeight [320*256]
  239.     move.w    BMP_Width(a4),d0    ;d0 = PicWidth    [Chunky]    [320]
  240.     lsr.w    #3,d0    ;d0 = PicWidth/8 [Planar]  [320/8]
  241.     mulu    BMP_Height(a4),d0    ;d0 = Size of a planar bitplane.
  242.  
  243.     move.l    GS_Attrib(a0),d1    ;d1 = Screen attributes
  244.     and.l    #DBLBUFFER|TPLBUFFER,d1    ;d1 = Double or triple buffered?
  245.     bne.s    .doubleandtriple    :>> = Yes.
  246.  
  247. .single    move.l    GS_EMemPtr1(a0),a1    ;a1 = Pointer to planar display.
  248.     move.l    GS_MemPtr1(a0),a0    ;a0 = Pointer to chunky buffer.
  249.     bra.s    .process
  250.  
  251. .doubleandtriple
  252.     move.l    GS_EMemPtr2(a0),a1    ;a1 = Pointer to planar display.
  253.     move.l    GS_MemPtr2(a0),a0    ;a0 = Pointer to chunky buffer.
  254.  
  255. .process
  256.     lea    (a1,d0.l*2),a2    ;a2 = Plane 2.
  257.     lea    (a2,d0.l*2),a3    ;a3 = Plane 4.
  258.     lea    (a3,d0.l*2),a4    ;a4 = Plane 6.
  259.     lea    (a4,d0.l),a5    ;a5 = Plane 7.
  260.     move.l    a0,a6    ;a6 = Start of chunky plane.
  261.     add.l    d5,a6    ;a6 = End of chunky plane.
  262.  
  263.     ;a0 = Chunky buffer
  264.     ;a1 = Plane 0
  265.     ;a1 = Plane 1
  266.     ;a2 = Plane 2
  267.     ;a2 = Plane 3
  268.     ;a3 = Plane 4
  269.     ;a3 = Plane 5
  270.     ;a4 = Plane 6
  271.     ;a5 = Plane 7
  272.     ;a6 = End of chunky plane.
  273.     ;
  274.     ;d6 = Chunky byte.
  275.     ;d7 = Pixel position in planar destination.
  276.  
  277. .copy    moveq    #8-1,d7    ;d7 = 8 pixels to copy across.
  278.     moveq    #$00,d1
  279.     moveq    #$00,d2
  280.     moveq    #$00,d3
  281.     moveq    #$00,d4
  282.     moveq    #$00,d5
  283.     clr.b    (a3,d0.l)
  284.     clr.b    (a4)
  285.     clr.b    (a5)
  286. .loop    move.b    (a0)+,d6    ;d6 = Chunky byte.
  287. .bit0    btst    #0,d6
  288.     beq.s    .bit1
  289.     bset    d7,d1
  290. .bit1    btst    #1,d6
  291.     beq.s    .bit2
  292.     bset    d7,d2
  293. .bit2    btst    #2,d6
  294.     beq.s    .bit3
  295.     bset    d7,d3
  296. .bit3    btst    #3,d6
  297.     beq.s    .bit4
  298.     bset    d7,d4
  299. .bit4    btst    #4,d6
  300.     beq.s    .bit5
  301.     bset    d7,d5
  302. .bit5    btst    #5,d6
  303.     beq.s    .bit6
  304.     bset    d7,(a3,d0.l)
  305. .bit6    btst    #6,d6
  306.     beq.s    .bit7
  307.     bset    d7,(a4)
  308. .bit7    btst    #7,d6
  309.     beq.s    .done
  310.     bset    d7,(a5)
  311. .done    dbra    d7,.loop    ;d7 = --1 and loop.
  312.  
  313.     move.b    d2,(a1,d0.l)
  314.     move.b    d1,(a1)+
  315.     move.b    d4,(a2,d0.l)
  316.     move.b    d3,(a2)+
  317.     move.b    d5,(a3)+
  318.     addq.w    #1,a4
  319.     addq.w    #1,a5
  320.     cmp.l    a0,a6
  321.     bne.s    .copy
  322.     MOVEM.L    (SP)+,D0-D7/A0-A6    ;SP = Return used registers.
  323.     rts
  324.  
  325. ;===================================================================================;
  326. ;                                       DATA
  327. ;===================================================================================;
  328.  
  329. DPKBase    dc.l    0
  330. CHKBase dc.l    0
  331.  
  332. ;-----------------------------------------------------------------------------------;
  333. EndCode:
  334.